#include "Billboard.h"
#include <gl\glut.h>

Billboard::Billboard() : m_verticalVec(0,1,0)
{
	m_vertical = false;
}

Billboard::Billboard(bool b)
{
	m_vertical = b;
}

void Billboard::Draw()
{
	//Get model view matrix
	float mv[16];
	glGetFloatv(GL_MODELVIEW_MATRIX, mv);


	//work out right and up vectors
	Vec3f right(mv[0], mv[4], mv[8]);
	Vec3f up;
	if(m_vertical)
	{
		up = m_verticalVec;		
	}
	else
	{
		up = Vec3f(mv[1], mv[5], mv[9]);
	}
	//work out corner coords and draw quad

	Vec3f topRight = up + right;
	Vec3f topLeft = up - right;
	Vec3f bottomRight = Vec3f(0,0,0) - up + right;
	Vec3f bottomLeft = Vec3f(0,0,0) - up - right;

	glBegin(GL_QUADS);

	glTexCoord2f(1,0);
	glVertex3f(topRight.X, topRight.Y, topRight.Z);

	glTexCoord2f(1,1);
	glVertex3f(bottomRight.X, bottomRight.Y, bottomRight.Z);

	glTexCoord2f(0,1);
	glVertex3f(bottomLeft.X, bottomLeft.Y, bottomLeft.Z);

	glTexCoord2f(0,0);
	glVertex3f(topLeft.X, topLeft.Y, topLeft.Z);

	glEnd();
}